//
//  MYGScheduleDetailViewController.swift
//  MYDoctor
//
//  Created by 王振明 on 2024/5/5.
//

import UIKit
import Photos
import QMUIKit

class MYGScheduleDetailViewController: MYGBaseController {
    var scheModel:MYGScheduleListModel = MYGScheduleListModel()
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        self.title = "查看日程"
        configUI()
        //        NotificationCenter.default.addObserver(self, selector: #selector(getAllSchedules(noti:)), name: NSNotification.Name.init("MYGScheduleRefresh"), object: nil)
    }
    //    @objc func getAllSchedules(noti:NSNotification){
    //        scheModel = noti.object as! MYGScheduleListModel
    //        for vi in view.subviews {
    //            vi.removeFromSuperview()
    //        }
    //        titleLab.text = scheModel.name
    //        dateLabel.text = scheModel.set_date
    //        timeLabel.text = "\(scheModel.start_at) - \(scheModel.end_at)"
    //        adressLabel.text = scheModel.schedule_address
    //        contentLabel.text = scheModel.describe
    //        huichangLabel.text = "会场：\(scheModel.schedule_site)"
    //        jiangtiLabel.text = "讲题：\(scheModel.schedule_theme)"
    //        huiyiLabel.text = "\(scheModel.schedule_type)：\(scheModel.schedule_number)"
    //        guard let jsonData = scheModel.image.data(using: .utf8) else {
    //            fatalError("Failed to convert JSON string to data.")
    //        }
    //        do {
    //            guard let jsonObject = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String] else {
    //                fatalError("Failed to deserialize JSON data.")
    //            }
    //            imageV.sd_setImage(with: URL(string: jsonObject[0]))
    //        } catch {
    //            print("Error: \(error)")
    //        }
    //        configUI()
    //    }
    @objc func shareAction(){
        UIViewController.keyWindow?.addSubview(shareFullView)
        shareFullView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    @objc func editAction(){
        let vc = MYGAddScheduleViewController()
        self.navigationController?.pushViewController(vc)
        vc.model = scheModel
    }
    @objc func cancelAction(){
        shareFullView.removeFromSuperview()
    }
    @objc func wechatShareAction(){
        //        let msg = UMSocialMessageObject.init()
        //        let share = UMShareWebpageObject.shareObject(withTitle: nil, descr: nil, thumImage: topshareView.createToImage())
        //        //        share?.webpageUrl = "www.baidu.com"
        //        msg.shareObject = share
        //        UMSocialManager.default().share(to: UMSocialPlatformType.wechatSession, messageObject: msg, currentViewController: self) { Data, error in
        //            if let er = error {
        //                print(er)
        //            }
        //        }
        let textToShare:String = "医路通"
        let imageToShare:UIImage = self.topshareView.createToImage() ?? UIImage()
        let activityItems:Array = [textToShare, imageToShare] as [Any]
        let activityVC:UIActivityViewController = UIActivityViewController.init(activityItems: activityItems, applicationActivities: nil)
        activityVC.excludedActivityTypes = [UIActivity.ActivityType.postToFacebook,UIActivity.ActivityType.airDrop]
        
        self.navigationController?.present(activityVC, animated: true)
    }
    @objc func friendShareAction(){
        shareFullView.removeFromSuperview()
    }
    @objc func qqShareAction(){
        //        let msg = UMSocialMessageObject.init()
        //        let share = UMShareWebpageObject.shareObject(withTitle: nil, descr: nil, thumImage: topshareView.createToImage())
        //        //        share?.webpageUrl = "www.baidu.com"
        //        msg.shareObject = share
        //        UMSocialManager.default().share(to: UMSocialPlatformType.QQ, messageObject: msg, currentViewController: self) { Data, error in
        //            if let er = error {
        //                print(er)
        //            }
        //        }
    }
    @objc func seeAll(){
        MYGLoading.show()
        MMYGNetwork<MYGScheduleAPI, MYGMeetingRoomListModel>.request(target: .showMeetingInfo(param: ["session_id":scheModel.sessionId])) {[weak self] result in
            MYGLoading.hide()
            let vc = MYGMeetingListDetailViewController()
            vc.mod = result
            self?.navigationController?.pushViewController(vc)
        } failed: { _, error in
            MYGLoading.hide()
            MMYGHUD.showToast(text: error)
        }
    }
    @objc func saveAction(){
        PHPhotoLibrary.requestAuthorization { status in
            if status == .authorized {
                // 保存图片到相册
                UIImageWriteToSavedPhotosAlbum(self.topshareView.createToImage() ?? UIImage(), nil, nil, nil)
                DispatchQueue.main.async {
                    self.shareFullView.removeFromSuperview()
                    MMYGHUD.showToast(text: "保存成功")
                }
            }
        }
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let barBtnItem:UIBarButtonItem = UIBarButtonItem(customView: backBtn)
        self.navigationItem.leftBarButtonItem = barBtnItem
        let shareBtnItem:UIBarButtonItem = UIBarButtonItem(customView: shareBtn)
        let editBtnItem:UIBarButtonItem = UIBarButtonItem(customView: editbtn)
        self.navigationItem.rightBarButtonItems = [shareBtnItem,editBtnItem]
    }
    private func configUI(){
        // 通过UIColor对象设置导航栏的背景颜色
        navigationController?.navigationBar.barTintColor = UIColor.clear
        navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white]
        view.addSubview(headImageV)
        headImageV.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.height.equalTo(statusBarHeight + 44)
            make.top.equalToSuperview().offset(-statusBarHeight - 44)
        }
        view.addSubview(scView)
        scView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        scView.addSubview(scContanerView)
        scContanerView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
            make.width.equalTo(screenWidth)
        }
        scContanerView.addSubviews([titleView,titleLab,timeImageV,timeLabel,adressImageV,adressLabel,contentLabel,huichangLabel,jiangtiLabel,taskLabel,huiyiImageV,huiyiLabel,lineView1,lineView2,lineView3,imageV])
        titleView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(20.5)
            make.top.equalToSuperview().offset(27.5)
            make.size.equalTo(CGSize(width: 15, height: 15))
        }
        titleLab.snp.makeConstraints { make in
            make.left.equalTo(titleView.snp.right).offset(13)
            make.top.equalToSuperview().offset(18.5)
            make.right.equalToSuperview().offset(-25)
        }
        //        dateLabel.snp.makeConstraints { make in
        //            make.left.equalToSuperview().offset(48.5)
        //            make.top.equalTo(titleLab.snp.bottom).offset(7.5)
        //            make.height.equalTo(21)
        //        }
        lineView1.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(48.5)
            make.right.equalToSuperview().offset(-30)
            make.top.equalTo(titleLab.snp.bottom).offset(17.5)
            make.height.equalTo(1)
        }
        timeImageV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(18.5)
            make.top.equalTo(titleLab.snp.bottom).offset(34.5)
            make.size.equalTo(CGSize(width: 19, height: 19))
        }
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(timeImageV.snp.right).offset(11)
            make.centerY.equalTo(timeImageV)
            make.height.equalTo(20)
        }
        lineView2.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(48.5)
            make.right.equalToSuperview().offset(-30)
            make.top.equalTo(timeLabel.snp.bottom).offset(17.5)
            make.height.equalTo(1)
        }
        
        adressImageV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(18.5)
            make.top.equalTo(lineView2.snp.bottom).offset(scheModel.schedule_address.count != 0 ? 17 : 0)
            make.size.equalTo(scheModel.schedule_address.count != 0 ? CGSize(width: 19, height: 19) : CGSize(width: 0, height: 0))
        }
        adressLabel.snp.makeConstraints { make in
            make.left.equalTo(adressImageV.snp.right).offset(11)
            make.centerY.equalTo(adressImageV)
            make.height.equalTo(scheModel.schedule_address.count != 0 ? 20 : 0)
        }
        lineView3.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(48.5)
            make.right.equalToSuperview().offset(-30)
            make.top.equalTo(adressLabel.snp.bottom).offset(scheModel.schedule_address.count == 0 ? 0 : 17.5)
            make.height.equalTo(1)
        }
        
        if scheModel.schedule_address.count == 0{
            //            adressImageV.snp.updateConstraints { make in
            //                make.size.equalTo(CGSize(width: 19, height: 0))
            //            }
            //            adressLabel.snp.updateConstraints { make in
            //                make.height.equalTo(0)
            //            }
            lineView3.isHidden = true
        }
        
        contentLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(23)
            make.right.equalToSuperview().offset(-23)
            make.top.equalTo(lineView3.snp.bottom).offset(17)
        }
        //        huiyiAdressLabel.snp.makeConstraints { make in
        //            make.left.equalToSuperview().offset(23)
        //            make.top.equalTo(contentLabel.snp.bottom).offset(12)
        //            make.height.equalTo(scheModel.schedule_address.count > 0 ? 20 : 0)
        //            make.right.equalToSuperview().offset(-23)
        //        }
        huichangLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(23)
            make.right.equalToSuperview().offset(-23)
            make.top.equalTo(contentLabel.snp.bottom).offset(12)
            make.height.equalTo(scheModel.schedule_site.count > 0 ? 20 : 0)
        }
        jiangtiLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(23)
            make.right.equalToSuperview().offset(-23)
            make.top.equalTo(huichangLabel.snp.bottom).offset(7.5)
            make.height.equalTo(scheModel.schedule_theme.count > 0 ? 20 : 0)
        }
        taskLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(23)
            make.right.equalToSuperview().offset(-23)
            make.top.equalTo(jiangtiLabel.snp.bottom).offset(7.5)
            make.height.equalTo(scheModel.task.count > 0 ? 20 : 0)
        }
        huiyiImageV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(23)
            make.top.equalTo(taskLabel.snp.bottom).offset(9)
            make.size.equalTo(CGSize(width: 17, height: 17))
        }
        huiyiImageV.isHidden = scheModel.schedule_number.count > 0 ? false : true
        huiyiLabel.snp.makeConstraints { make in
            make.left.equalTo(huiyiImageV.snp.right).offset(11)
            make.centerY.equalTo(huiyiImageV)
            make.right.equalToSuperview().offset(-23)
        }
        huiyiLabel.isHidden = scheModel.schedule_number.count > 0 ? false : true
        imageV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(23)
            make.top.equalTo(huiyiLabel.snp.bottom).offset(9)
            make.width.height.equalTo(150)
            make.bottom.equalToSuperview().offset(-20)
        }
        
        if scheModel.sessionId > 0 {
            view.addSubview(seeAllBtn)
            seeAllBtn.snp.makeConstraints { make in
                make.left.equalToSuperview().offset(54)
                make.right.equalToSuperview().offset(-54)
                make.height.equalTo(40)
                make.bottom.equalToSuperview().offset(-30)
            }
        }
    }
    //MARK: lazy
    lazy var shareFullView:UIView = {
        let shareView = UIView()
        shareView.backgroundColor = .rgba(0, 0, 0,0.4)
        
        shareView.addSubview(shareBottomView)
        shareBottomView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(140)
        }
        var topWidth = screenWidth - 40
        var topHeight = screenHeight - 140 - SCALEWIDTH(140)
        if scContanerView.height + 80 > topHeight{
            topWidth = topHeight * 334.5 / 600
        }else{
            topHeight = scContanerView.height + 80
        }

        shareView.addSubview(topshareView)
        topshareView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalTo(shareBottomView.snp.top).offset(-31)
            make.width.equalTo(topWidth)
            make.height.equalTo(topHeight)
        }
        
        let cancelBtn = UIButton(type: .custom)
        cancelBtn.setImage(UIImage(named: "schedule_cancel"), for: .normal)
        cancelBtn.addTarget(self, action: #selector(cancelAction), for: .touchUpInside)
        shareView.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { make in
            make.right.equalTo(topshareView.snp.right).offset(-12)
            make.top.equalTo(topshareView.snp.top).offset(12)
            make.height.width.equalTo(13)
        }
        return shareView
    }()
    lazy var topshareView:UIView = {
        let cont = UIView()
        let image = scContanerView.createToImage()
        
        let imageView = UIImageView(image: image)
        imageView.backgroundColor = .white
        cont.addSubview(imageView)
        imageView.snp.makeConstraints { make in
            make.left.right.top.equalToSuperview()
            make.bottom.equalToSuperview().offset(-80)
        }
        cont.addSubview(appInfoView)
        appInfoView.snp.makeConstraints { make in
            make.left.bottom.right.equalToSuperview()
            make.height.equalTo(80)
        }
        return cont
    }()
    lazy var shareBottomView: UIView = {
        let control = UIView()
        control.backgroundColor = .white
        let lab = UILabel()
        lab.text = "推荐给朋友"
        lab.textColor = .rgba(35, 35, 35, 1)
        lab.font = .regular(16)
        control.addSubview(lab)
        lab.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(33)
            make.top.equalToSuperview().offset(21)
            make.height.equalTo(22.5)
        }
        
        let cancelBtn = UIButton(type: .custom)
        cancelBtn.setImage(UIImage(named: "schedule_cancel"), for: .normal)
        cancelBtn.addTarget(self, action: #selector(cancelAction), for: .touchUpInside)
        control.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-12)
            make.top.equalToSuperview().offset(12)
            make.height.width.equalTo(13)
        }
        
        let wechatBtn = UIButton(type: .custom)
        wechatBtn.setImage(UIImage(named: "schedule_wechat"), for: .normal)
        wechatBtn.addTarget(self, action: #selector(wechatShareAction), for: .touchUpInside)
        control.addSubview(wechatBtn)
        wechatBtn.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(33)
            make.top.equalToSuperview().offset(58.5)
            make.height.width.equalTo(50)
        }
        
        let wechatLab = UILabel()
        wechatLab.text = "微信"
        wechatLab.textColor = .rgba(35, 35, 35, 1)
        wechatLab.font = .regular(14)
        control.addSubview(wechatLab)
        wechatLab.snp.makeConstraints { make in
            make.centerX.equalTo(wechatBtn)
            make.top.equalTo(wechatBtn.snp.bottom).offset(4)
            make.height.equalTo(20)
        }
        
        //        let friendBtn = UIButton(type: .custom)
        //        friendBtn.setImage(UIImage(named: "schedule_friendCircle"), for: .normal)
        //        friendBtn.addTarget(self, action: #selector(friendShareAction), for: .touchUpInside)
        //        control.addSubview(friendBtn)
        //        friendBtn.snp.makeConstraints { make in
        //            make.centerX.equalToSuperview()
        //            make.top.equalToSuperview().offset(58.5)
        //            make.height.width.equalTo(50)
        //        }
        
        //        let friendLab = UILabel()
        //        friendLab.text = "朋友圈"
        //        friendLab.textColor = .rgba(35, 35, 35, 1)
        //        friendLab.font = .regular(14)
        //        control.addSubview(friendLab)
        //        friendLab.snp.makeConstraints { make in
        //            make.centerX.equalTo(friendBtn)
        //            make.top.equalTo(friendBtn.snp.bottom).offset(4)
        //            make.height.equalTo(20)
        //        }
        
        //        let qqbtn = UIButton(type: .custom)
        //        qqbtn.setImage(UIImage(named: "schedule_qq"), for: .normal)
        //        qqbtn.addTarget(self, action: #selector(qqShareAction), for: .touchUpInside)
        //        control.addSubview(qqbtn)
        //        qqbtn.snp.makeConstraints { make in
        //            make.right.equalToSuperview().offset(-33)
        //            make.top.equalToSuperview().offset(58.5)
        //            make.height.width.equalTo(50)
        //        }
        //
        //        let qqlabl = UILabel()
        //        qqlabl.text = "QQ"
        //        qqlabl.textColor = .rgba(35, 35, 35, 1)
        //        qqlabl.font = .regular(14)
        //        control.addSubview(qqlabl)
        //        qqlabl.snp.makeConstraints { make in
        //            make.centerX.equalTo(qqbtn)
        //            make.top.equalTo(qqbtn.snp.bottom).offset(4)
        //            make.height.equalTo(20)
        //        }
        
        let saveBtn = UIButton(type: .custom)
        saveBtn.setImage(UIImage(named: "schedule_save"), for: .normal)
        saveBtn.addTarget(self, action: #selector(saveAction), for: .touchUpInside)
        control.addSubview(saveBtn)
        saveBtn.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(58.5)
            make.height.width.equalTo(50)
        }
        
        let saveLabe = UILabel()
        saveLabe.text = "保存图片"
        saveLabe.textColor = .rgba(35, 35, 35, 1)
        saveLabe.font = .regular(14)
        control.addSubview(saveLabe)
        saveLabe.snp.makeConstraints { make in
            make.centerX.equalTo(saveBtn)
            make.top.equalTo(saveBtn.snp.bottom).offset(4)
            make.height.equalTo(20)
        }
        
        return control
    }()
    lazy var appInfoView: UIView = {
        var topWidth = screenWidth - 40
        var topHeight = screenHeight - 246.5 - 140
        if scContanerView.height + 80 > topHeight{
            topWidth = topHeight * 334.5 / 652.5
        }else{
            topHeight = scContanerView.height + 80
        }
        
        let control = UIView()
        control.backgroundColor = .rgba(244, 244, 244)
        let lab = UILabel()
        lab.text = "医"
        lab.backgroundColor = .rgba(89, 97, 245, 1)
        lab.textAlignment = .center
        lab.textColor = .white
        lab.font = .medium(12*topWidth/334)
        lab.layerCornerRadius = 11*topWidth/334
        control.addSubview(lab)
        lab.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(24*topWidth/334)
            make.centerY.equalToSuperview()
            make.height.width.equalTo(22*topWidth/334)
        }
        
        let wechatLab = UILabel()
        wechatLab.text = "医路通"
        wechatLab.textColor = .rgba(89, 97, 245, 1)
        wechatLab.font = .semibold(16*topWidth/334)
        control.addSubview(wechatLab)
        wechatLab.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.height.equalTo(22.5*topWidth/334)
            make.left.equalTo(lab.snp.right).offset(8*topWidth/334)
        }
        
        let imgV = UIImageView()
//        imgV.backgroundColor = .black
        imgV.image = UIImage(named: "AppIcon")
        imgV.layerCornerRadius = 2.5*topWidth/334
        control.addSubview(imgV)
        imgV.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-20*topWidth/334)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(60*topWidth/334)
        }
        return control
    }()
    lazy var backBtn: UIButton = {
        let control = UIButton(type: .custom)
        control.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
        control.tintColor = .white
        control.setImage(UIImage(named: "Chat/back"), for: .normal)
        control.addTarget(self, action: #selector(backAction), for: .touchUpInside)
        return control
    }()
    lazy var shareBtn: UIButton = {
        let control = UIButton(type: .custom)
        control.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
        control.tintColor = .white
        control.setImage(UIImage(named: "scheduleDetail_share"), for: .normal)
        control.addTarget(self, action: #selector(shareAction), for: .touchUpInside)
        return control
    }()
    lazy var editbtn: UIButton = {
        let control = UIButton(type: .custom)
        control.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
        control.tintColor = .white
        control.setImage(UIImage(named: "scheduleDetail_edit"), for: .normal)
        control.addTarget(self, action: #selector(editAction), for: .touchUpInside)
        return control
    }()
    private lazy var headImageV:UIImageView = {
        let cont = UIImageView()
        cont.image = UIImage(named: "schedule_head")
        return cont
    }()
    private lazy var scView:UIScrollView = {
        let cont = UIScrollView()
        cont.isUserInteractionEnabled = true
        return cont
    }()
    private lazy var scContanerView:UIView = {
        let cont = UIView()
        cont.isUserInteractionEnabled = true
        return cont
    }()
    private lazy var titleView:UIView = {
        let cont = UIView()
        cont.backgroundColor = .rgba(78, 87, 240, 1)
        return cont
    }()
    lazy var titleLab:UILabel = {
        let cont = UILabel()
        cont.textColor = .rgba(47, 47, 77, 1)
        cont.font = .medium(24)
        cont.numberOfLines = 0
        cont.text = scheModel.name
        return cont
    }()
    //    lazy var dateLabel:UILabel = {
    //        let cont = UILabel()
    //        cont.textColor = .rgba(47, 47, 77, 0.6)
    //        cont.font = .medium(15)
    //        //        if scheModel.set_date.count > 0{
    //        //            let startIndex = scheModel.set_date.index(scheModel.set_date.startIndex, offsetBy: 0)
    //        //            let endIndex = scheModel.set_date.index(scheModel.set_date.startIndex, offsetBy: 10)
    //        //            cont.text = String(scheModel.set_date[startIndex..<endIndex])
    //        //        }
    //        cont.text = String(scheModel.set_date.prefix(10))
    //        return cont
    //    }()
    lazy var timeLabel:UILabel = {
        let cont = UILabel()
        cont.textColor = .rgba(47, 47, 77, 1)
        cont.font = .medium(14)
        cont.text = "\(scheModel.start_at) - \(scheModel.end_at)"
        return cont
    }()
    lazy var adressLabel:UILabel = {
        let cont = UILabel()
        cont.textColor = .rgba(47, 47, 77, 1)
        cont.font = .medium(14)
        cont.text = scheModel.schedule_address
        return cont
    }()
    lazy var contentLabel:UILabel = {
        let cont = UILabel()
        cont.textColor = .rgba(93, 93, 93, 1)
        cont.font = .medium(14)
        cont.numberOfLines = 0
        cont.text = scheModel.describe
        return cont
    }()
    //    lazy var huiyiAdressLabel:UILabel = {
    //        let cont = UILabel()
    //        cont.textColor = .rgba(47, 47, 77, 1)
    //        cont.font = .medium(14)
    //        cont.text = "会议地址：\(scheModel.schedule_address)"
    //        return cont
    //    }()
    lazy var huichangLabel:UILabel = {
        let cont = UILabel()
        cont.textColor = .rgba(47, 47, 77, 1)
        cont.font = .medium(14)
        cont.text = "会场：\(scheModel.schedule_site)"
        return cont
    }()
    lazy var jiangtiLabel:UILabel = {
        let cont = UILabel()
        cont.textColor = .rgba(47, 47, 77, 1)
        cont.font = .medium(14)
        cont.text = "讲题：\(scheModel.schedule_theme)"
        return cont
    }()
    lazy var taskLabel:UILabel = {
        let cont = UILabel()
        cont.textColor = .rgba(47, 47, 77, 1)
        cont.font = .medium(14)
        cont.text = "角色：\(scheModel.task)"
        return cont
    }()
    lazy var huiyiLabel:UILabel = {
        let cont = UILabel()
        cont.textColor = .rgba(64, 143, 245, 1)
        cont.font = .medium(14)
        cont.text = "\(scheModel.schedule_type)：\(scheModel.schedule_number)"
        return cont
    }()
    lazy var timeImageV:UIImageView = {
        let cont = UIImageView()
        cont.image = UIImage(named: "scheduleDetail_time")
        return cont
    }()
    lazy var adressImageV:UIImageView = {
        let cont = UIImageView()
        cont.image = UIImage(named: "scheduleDetail_adress")
        return cont
    }()
    lazy var huiyiImageV:UIImageView = {
        let cont = UIImageView()
        cont.image = UIImage(named: "scheduleDetail_huiyi")
        return cont
    }()
    lazy var lineView1:UIView = {
        let cont = UIView()
        cont.backgroundColor = .rgba(47, 47, 47,0.1)
        return cont
    }()
    lazy var lineView2:UIView = {
        let cont = UIView()
        cont.backgroundColor = .rgba(47, 47, 47,0.1)
        return cont
    }()
    lazy var lineView3:UIView = {
        let cont = UIView()
        cont.backgroundColor = .rgba(47, 47, 47,0.1)
        return cont
    }()
    lazy var seeAllBtn:UIButton = {
        let cont = UIButton()
        cont.backgroundColor = .rgba(89, 97, 245,1)
        cont.setTitle("查看全部会议", for: .normal)
        cont.setTitleColor(.white, for: .normal)
        cont.titleLabel?.font = .regular(16)
        cont.layerCornerRadius = 20
        cont.addTarget(self, action: #selector(seeAll), for: .touchUpInside)
        return cont
    }()
    lazy var imageV:UIImageView = {
        let cont = UIImageView()
        cont.layer.masksToBounds = true
        cont.layer.cornerRadius = 5
        cont.contentMode = .scaleAspectFill
        guard let jsonData = scheModel.image.data(using: .utf8) else {
            fatalError("Failed to convert JSON string to data.")
        }
        do {
            guard let jsonObject = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String] else {
                fatalError("Failed to deserialize JSON data.")
            }
            cont.sd_setImage(with: URL(string: jsonObject[0]))
        } catch {
            print("Error: \(error)")
        }
        cont.isUserInteractionEnabled = true
        let tap = UITapGestureRecognizer(target: self, action: #selector(showBigImage))
        cont.addGestureRecognizer(tap)
        return cont
    }()
    
}
extension MYGScheduleDetailViewController{
    @objc func showBigImage(){
        let vc = QMUIImagePreviewViewController()
        vc.imagePreviewView.delegate = self
        vc.imagePreviewView.currentImageIndex = 0
        vc.sourceImageView = {
            return self.imageV
        }
        vc.presentingStyle = .zoom
        vc.dismissingStyle = .fade
        UIViewController.currentViewController?.present(vc, animated: true)
    }
}
extension MYGScheduleDetailViewController: QMUIImagePreviewViewDelegate {
    func numberOfImages(in imagePreviewView: QMUIImagePreviewView!) -> UInt {
        return 1
    }
    
    func imagePreviewView(_ imagePreviewView: QMUIImagePreviewView!, renderZoomImageView zoomImageView: QMUIZoomImageView!, at index: UInt) {
        zoomImageView.image = imageV.image
    }
}
